<?php

// $Id$

require_once(TANGRA_MAIN_DIR.'nls/date.inc.php');


class TCMS_VPage extends Tangra_Class {
	private $id;
	private $path;
	private $template;
	private $online = 0;
	private $created;
	private $last_modified;
	private $cache;
	private $cache_expiry = 0;
	private $created_by = 0;
	private $cache_locked = 0;
	private $last_modified_by = 0;
	private $sys_generated = false;
	private $in_sitemap = true;
	private $sitemap_weight = 5; // 0.5
	private $sitemap_change_freq = 4; // montly


	public function set_id($id) {
		tangra_if_not_int_throw_e($id);

		$this->id = $id;
	}


	public function get_id() {
		return $this->id;
	}


	public function set_path($path) {
		$this->path = $path;
	}


	public function get_path() {
		return $this->path;
	}


	public function set_online($online) {
		$this->online = $online ? true : false;
	}


	public function get_online() {
		return $this->online;
	}


	public function set_template($template) {
		tangra_if_not_int_throw_e($template);

		$this->template = $template;
	}


	public function get_template() {
		return $this->template;
	}


	protected function set_created($created) {
		if (check_timestamp($created)) {
			$this->created = $created;
		} else {
			throw new Tangra_Module_Exception('Invalid datetime in $created: '.$created);
		}
	}


	public function get_created() {
		return $this->created;
	}


	protected function set_last_modified($last_modified) {
		if (check_timestamp($last_modified)) {
			$this->last_modified = $last_modified;
		} else {
			throw new Tangra_Module_Exception('Invalid datetime in $last_modified: '.$last_modified);
		}
	}


	public function get_last_modified() {
		return $this->last_modified;
	}


	public function set_cache($cache) {
		$this->cache = $cache ? true : false;
	}


	public function get_cache() {
		return $this->cache;
	}


	public function set_cache_expiry($cache_expiry) {
		tangra_if_not_int_throw_e($cache_expiry);


		$this->cache_expiry = $cache_expiry;
	}


	public function get_cache_expiry() {
		return $this->cache_expiry;
	}


	public function set_cache_locked($cache_locked) {
		$this->cache_locked = $cache_locked ? true : false;
	}


	public function get_cache_locked() {
		return $this->cache_locked;
	}


	public function set_created_by($created_by) {
		tangra_if_not_int_throw_e($created_by);

		$this->created_by = $created_by;
	}


	public function get_created_by() {
		return $this->created_by;
	}


	public function set_last_modified_by($last_modified_by) {
		tangra_if_not_int_throw_e($last_modified_by);

		$this->last_modified_by = $last_modified_by;
	}


	public function get_last_modified_by() {
		return $this->last_modified_by;
	}


	public function set_sys_generated($sys_generated) {
		$this->sys_generated = $sys_generated ? true : false;
	}


	public function get_sys_generated() {
		return $this->sys_generated;
	}


	public function set_in_sitemap($in_sitemap) {
		$this->in_sitemap = $in_sitemap ? true : false;
	}


	public function get_in_sitemap() {
		return $this->in_sitemap;
	}


	public function set_sitemap_weight($sitemap_weight) {
		tangra_if_not_int_throw_e($sitemap_weight);

		if (self::is_valid_weight($sitemap_weight)) {
			$this->sitemap_weight = $sitemap_weight;
		} else {
			throw new Tangra_Module_Exception('Invalid value for parameter $sitemap_weight: '.$sitemap_weight);
		}
	}


	public function get_sitemap_weight() {
		return $this->sitemap_weight;
	}


	public function set_sitemap_change_freq($sitemap_change_freq) {
		tangra_if_not_int_throw_e($sitemap_change_freq);

		$this->sitemap_change_freq = $sitemap_change_freq;
	}


	public function get_sitemap_change_freq() {
		return $this->sitemap_change_freq;
	}
	
	
	public static function is_valid_weight($sitemap_weight) {
		if ($sitemap_weight >= 0 && $sitemap_weight <= 10) {
			return true;
		} else {
			return false;
		}
	}
}